//
//  ZJEmtionPicureView.swift
//  Webo
//
//  Created by 曾静 on 16/7/4.
//  Copyright © 2016年 qq. All rights reserved.
//

import UIKit


private let emtionPicureViewId = "emtionPicureViewId"
class ZJEmtionPicureView: UICollectionView {

    
    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        self.pagingEnabled = true
        
        self.showsHorizontalScrollIndicator = false
        
        self.showsVerticalScrollIndicator = false
        
        self.bounces = false
        
        dataSource = self
        
        
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){
        
        backgroundColor  = UIColor.redColor()
        
        //注册cell
        
        registerClass(ZJEmotionPictureCell.self, forCellWithReuseIdentifier: emtionPicureViewId)
        
        //设置lyout
        let layout = collectionViewLayout as!UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        
        layout.minimumInteritemSpacing = 0
        
        layout.minimumLineSpacing = 0
        
        
        //特别记住,滚动方向是在layout里面设置的
        layout.scrollDirection = .Horizontal
    
    }
    
}

extension ZJEmtionPicureView:UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return ZJEmotionTool.shareEmotionTools.allEmotions.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return ZJEmotionTool.shareEmotionTools.allEmotions[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(emtionPicureViewId, forIndexPath: indexPath) as!ZJEmotionPictureCell
        
//        cell.backgroundColor = RandomColor()
        
        cell.emotions = ZJEmotionTool.shareEmotionTools.allEmotions[indexPath.section][indexPath.item]
        cell.indexPath = indexPath
        
        return cell
    }
    
    
}
